package com.example.fairplay.newfpregistration.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.fairplay.newfpregistration.R;
import com.example.mylibrary.activity.BaseFragment;
import com.example.mylibrary.config.Config;
import com.example.mylibrary.util.PreferencesUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by fairplay on 2018/5/31.
 * 基础设置fragment
 */

public class BasicSystemFragment extends BaseFragment {


    @Bind(R.id.rb_plan1)
    RadioButton rbPlan1;
    @Bind(R.id.rb_plan2)
    RadioButton rbPlan2;
    @Bind(R.id.rb_plan3)
    RadioButton rbPlan3;
    @Bind(R.id.rg_basic_setting)
    RadioGroup rgBasicSetting;
    private View view;
    private boolean card_face_finger;
    private boolean face;
    private boolean card_finger;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_basic_setting, container, false);
        ButterKnife.bind(this, view);
        initObjects();
        initViews();
        initData();
        setListeners();
        return view;
    }


    @Override
    protected void findViews() {

    }

    @Override
    protected void initObjects() {
        card_face_finger = PreferencesUtils.getBoolean(Config.SETTING_CARD_FACE_FINGER, true);
        face = PreferencesUtils.getBoolean(Config.SETTING_FACE, false);
        card_finger = PreferencesUtils.getBoolean(Config.SETTING_CARD_FINGER, false);


    }

    @Override
    protected void initViews() {
        if (card_face_finger) {
            rbPlan1.setChecked(true);
        } else if (face) {
            rbPlan2.setChecked(true);
        } else if (card_finger) {
            rbPlan3.setChecked(true);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListeners() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.rb_plan1, R.id.rb_plan2, R.id.rb_plan3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rb_plan1:
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FACE_FINGER,true);
                PreferencesUtils.putBoolean(Config.SETTING_FACE,false);
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FINGER,false);
                break;
            case R.id.rb_plan2:
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FACE_FINGER,false);
                PreferencesUtils.putBoolean(Config.SETTING_FACE,true);
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FINGER,false);
                break;
            case R.id.rb_plan3:
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FACE_FINGER,false);
                PreferencesUtils.putBoolean(Config.SETTING_FACE,false);
                PreferencesUtils.putBoolean(Config.SETTING_CARD_FINGER,true);
                break;
        }
    }
}
